/**
 * This helper class helps to get the CORBA reference.
 */
package com.comp6231.replica2.server.helper;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import org.omg.CORBA.ORB;

public class ClientCORBAObject {

	public static StationInterfaceIDL getCORBAObj(StationID stationID) {
		// Initialize ORB
		ORB orb = ORB.init(new String[] { "" }, null);

		// Fetch for ior
		BufferedReader br = null;
		String ior = null;
		try {
			switch (stationID) {
			case SPVM:
				br = new BufferedReader(
						new FileReader(
								System.getProperty("user.dir")
										+ "/src/com/comp6231/replica2/server/helper/ior_spvm.txt"));
				break;
			case SPL:
				br = new BufferedReader(
						new FileReader(
								System.getProperty("user.dir")
										+ "/src/com/comp6231/replica2/server/helper/ior_spl.txt"));
				break;
			case SPB:
				br = new BufferedReader(
						new FileReader(
								System.getProperty("user.dir")
										+ "/src/com/comp6231/replica2/server/helper/ior_spb.txt"));
				break;
			default:
				break;
			}
			ior = br.readLine();
			br.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		// Transform the ior to CORBA object
		org.omg.CORBA.Object o = orb.string_to_object(ior);
		return StationInterfaceIDLHelper.narrow(o);
	}
}
